package com.ym.medical.service.impl;

import com.ym.core.utils.tkmybatis.BaseSVImpl;
import com.ym.medical.dao.OpenStudioReviewDao;
import com.ym.medical.domain.entity.DoctorStudioEntity;
import com.ym.medical.domain.entity.OpenStudioAppEntity;
import com.ym.medical.domain.entity.OpenStudioReviewEntity;
import com.ym.medical.enums.DoctorStudioStatusEnum;
import com.ym.medical.enums.StudioAppStatusEnum;
import com.ym.medical.enums.StudioReviewStatusEnum;
import com.ym.medical.service.IDoctorStudioSV;
import com.ym.medical.service.IOpenStudioAppSV;
import com.ym.medical.service.IOpenStudioReviewSV;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 工作室开通审核Service业务层处理
 *
 * @author ym
 * @date 2020-08-24
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OpenStudioReviewSVImpl extends BaseSVImpl<OpenStudioReviewEntity, OpenStudioReviewDao> implements IOpenStudioReviewSV {

	@Autowired
	private IOpenStudioAppSV openStudioAppSV;
	@Autowired
	private IDoctorStudioSV doctorStudioSV;

	@Override
	public int saveOpenStudioReview(OpenStudioReviewEntity openStudioReview) {
		this.insert(openStudioReview);
		OpenStudioAppEntity openStudioApp = openStudioAppSV.selectById(openStudioReview.getAppId());
		if(StudioReviewStatusEnum.THROUGH.getKey().equals(openStudioReview.getState())){//审核通过
			openStudioApp.setState(StudioAppStatusEnum.HAVE_BEEN_THROUGH.getKey());
		}else{//驳回
			openStudioApp.setState(StudioAppStatusEnum.HAS_BEEN_REJECTED.getKey());
		}
		openStudioAppSV.updateById(openStudioApp);
		DoctorStudioEntity doctorStudio = new DoctorStudioEntity();
		doctorStudio.setBelongPerson(openStudioApp.getDoctId());
		doctorStudio.setDsName(openStudioApp.getDsName());
		doctorStudio.setDescription(openStudioApp.getDescription());
		doctorStudio.setState(DoctorStudioStatusEnum.SHUT_DOWN.getKey());
		doctorStudioSV.insert(doctorStudio);
		return 1;
	}
}
